package com.coollang.smartbra.utils;

import android.content.Context;
import android.os.PowerManager;

/**
 * Created by Administrator on 2016/10/22 0022.
 */

public class PowerManagerUtils {
    static PowerManager.WakeLock mWakeLock;
    public static void unLockScreen() {
        PowerManager pm = (PowerManager) UIUtils.getContext().getSystemService(Context.POWER_SERVICE);
        mWakeLock= pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK , "MyTag");
        // in onResume() call //取消自动锁屏，onResume()方法中执行
        mWakeLock.acquire();
    }

    public static void lockScreen() {
        // in onPause() call //开启自动锁屏，onPause()方法中执行
        PowerManager pm = (PowerManager) UIUtils.getContext().getSystemService(Context.POWER_SERVICE);
        mWakeLock= pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK , "MyTag");
        if (mWakeLock.isHeld()){
            mWakeLock.release();
        }
    }

}
